<?php
  require("abifunktsioonid.php");
  session_start();
 if($_SESSION["group_type"]!="1"){
 header("Location: login.php");
 exit();
 }
 if(isSet($_REQUEST["lahku"])){
 unset($_SESSION["username"]);
  header("Location: login.php");
 exit();
 }
  
  if(isSet($_REQUEST["sisestusnupp"])){
    $kask=$yhendus->prepare(
        "UPDATE works SET w_hrs=? WHERE id=?");
	$kask->bind_param("di", $_REQUEST["w_hrs"], $_REQUEST["id"]); #Siit uuendatakse tabelit
	$kask->execute();
}
  
  $kask=$yhendus->prepare("SELECT works.id ,workdate, workdescription, w_hrs FROM works, workers, users  
  WHERE users.realname=workers.worker AND works.worker_id=workers.id AND users.username=? ");  #Siit tulevad ainult sisselogitud kaustaja andmed
  echo $yhendus->error;
  $kask->bind_param("s", $_SESSION["username"]);
  echo $yhendus->error;
  $kask->bind_result($id, $workdate, $workdescription, $w_hrs);
  $kask->execute();
  
 
?>

 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
 <meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="kujundus.css">
 <title>Bon Services OY</title>
</head>
  <body>
  <div id="main">
  <img id="header" src="bso.png" alt="logo" href="login.php"/>
  </div>
  <div id="main2">
  <div id="main3">
	<div id="sisu">
  Tere! Oled <?php echo $_SESSION["username"]; ?> 
  
  <table id="worker">
	 
		<tr>
			<th>Kuupäev</th>
			<th>Leping</th>		
			<th>Töötunnid</th>				
		</tr>

 <?php
  
  while ($kask->fetch()){ 
  echo"<tr>
		   <td>$workdate</td>
		   <td>$workdescription</td>
		   <td>$w_hrs</td>
		   <td> 
		   <form action='?'>
					<input type='hidden' name='id' value='$id'>
					<input type='text' name='w_hrs' />
					<input type='submit' name='sisestusnupp' value='Sisesta' />
			</form></td>
           
         </tr>"; #Siin toimub kogu info kuvamine ja ka sisestamine
  }
  ?> 
 
    </table>
 
</div>
  </div>
<div id="kasutaja">
	 <a href="login.php" id="tagasi">Tagasi</a>
	  <p id="kasutajad"><?php echo $_SESSION["username"]; ?>
 <a href="?lahku" id="lahku">lahku</a></p>
 </div>
  </div>
  </body>
</html>
